import * as moment from 'moment/moment';

export const HbsHelpers = {
  // 格式化日期方法
  formatDate: function (date: any, format: string = 'YYYY-MM-DD HH:mm:ss') {
    const instance = new Date(date);
    return moment(instance).format(format);
  },
  // 比较a,b是否一致，如果有result，则返回result 没有则返回boolean
  equal: function (a: any, b: any, result: any) {
    const f = a === b;
    if (result) {
      return f ? result : null;
    }
    return f;
  },
  // 获取指定数值长度的数组
  numberToArray: function (num: number) {
    return new Array(num).fill(null).map((_, i) => i);
  },
  // 两数相加
  summation: function (num: any, anum: any) {
    return num + anum;
  },
  // 两数相减
  decrease: function (num: any, anum: any) {
    return num - anum;
  },
  // 转为int
  parseInt: function (num: any) {
    return parseInt(num);
  },
  // 两数相乘
  multiply: function (num: any, anum: any) {
    return num * anum;
  },
  // 设置默认值
  defaultValue: function (value: any) {
    return value || '';
  },
};
